<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<title>JavaScript: The Good Parts - Constructor</title>
		<style type="text/css">
			div#header {
				color: #0066FF;
				font-size: 25pt;
			}
			
			div#content {
				color: #B088FF;
				font-size: 12pt;
			}
		</style>
		
		<!-- embed jquery by google，藉由google嵌入jquery 1.6.2 -->
		<script type="text/javascript" src="http://www.google.com/jsapi"></script>
		<script type="text/javascript" language="javascript">
			google.load( "jquery", "1.6.2" );
		</script>
		<script type="text/javascript">
		
			/****************************************************************************
			在javascript中，函式的呼叫有四種方式:
			此示範第三種，建構子呼叫模式(constructor invocation pattern)
			****************************************************************************/
		
			var Quo = function( string ) {
				if( !isInputArgumentVaild( string ) ) {
					return "The argument is invaild!";
				}
			
				this.status = string;
			};
			
			// 用來判別傳入函式的飲數是否合法
			var isInputArgumentVaild = function( arg0, arg1, arg2, arg3, arg4, arg5 ) {
				for( var i = 0; i < arguments.length; i++ ) {
					if( arguments[i] == null || typeof( arguments[i] ) === "undefined" ) {
						return false;
					} else if( arguments[i] === "" ) {
						return "";
					} else {
						return true;
					}
				}
			};
		
			$( document ).ready( function() {
				Quo.prototype.getStatus = function() {
					return this.status;
				};
				
				var myQuo = new Quo( "Super Man" );  // 呼叫建構子
				var myQuoStatus = myQuo.getStatus();
				$( "#content" ).append( "myQuo <strong>" + myQuoStatus + "</strong>");
			});
		</script>
		
	</head>
	
	<body>
		<div title="temp1" id="header">JavaScript: The Good Parts - Ch04 Function</div>
		<div title="temp1" id="content"></div>
	</body>
</html>